const path = require("path");
const HtmlWebpackPlugin = require('html-webpack-plugin');
const MiniCssExtractPlugin = require("mini-css-extract-plugin");
const webpackbar = require('webpackbar');
const webpack = require('webpack');

const Mock = require("mockjs");
const data = Mock.mock({
  "list|5": [{
    "text|5-10": "@cword",
    title: "@ctitle",
    img:"@image(100x100,@color)",
  }]
})
console.log(data)
module.exports = {
    entry: './src/index.js',
    output: {
        filename: 'main.js',
        path: path.resolve(__dirname, 'dist'),
        clean: true,
    },
    plugins: [
        // new webpack.optimize.UglifyJsPlugin(),
        new HtmlWebpackPlugin({ template: './src/index.html' }),
        new MiniCssExtractPlugin(),
        // 进度条
        new webpackbar(),
        new webpack.HotModuleReplacementPlugin({
            // Options...
        })
      ],
    mode: 'development',
    module: {
        rules: [{
          test: /\.s[ac]ss$/i,
          use: [
            // 将 JS 字符串生成为 style 节点
            MiniCssExtractPlugin.loader,
            // 将 CSS 转化成 CommonJS 模块
            'css-loader',
            // 将 Sass 编译成 CSS
            'sass-loader',
          ],
        },
        {
            test: /\.(png|jpg|gif)$/,
            use: [
              {
                loader: 'file-loader',
                options: {}
              }
            ]
            },
            {
                test: /\.js$/,
                exclude: /(node_modules|bower_components)/,
                use: {
                  loader: 'babel-loader',
                  options: {
                    presets: ['@babel/preset-env']
                  }
                }
            }
        ]
    },
    resolve: {
        alias: {
          css: path.resolve(__dirname, './src/sass'),
          img: path.resolve(__dirname, 'src/assert/img'),
        },
        extensions: ['.js', '.json','jpg'],
    },
    devServer: {
        host: 'localhost',
        port:8080,
        hot: true,
      open: true,
      before(app) {
        app.get('/move', (req, res) => {
          res.send(data.list);
        })
      }
    },
    devtool:'eval',
};

